let MS = require('./ms.js')
const request = require('./request.js')
const Error = require('./error')
const storage = require('./storage.js')

const {
    isObject,
    isString,
    isNumber,
    isUndefined,
    isBoolean,
    isArray
} = require('./dataType.js')

const goodsConsult = class goodsConsult {

    constructor() {

    }

    create(options) {
        let params = {}
        if(!isUndefined(options.goodsId) && isString(options.goodsId)) {
            params.goodsId = options.goodsId;
        }
        if(!isUndefined(options.userName) && isString(options.userName)) {
            params.userName = options.userName;
        }
        if(!isUndefined(options.phone) && isString(options.phone)) {
            params.phone = options.phone;
        }
        if(!isUndefined(options.email) && isString(options.email)) {
            params.email = options.email;
        }
        if(!isUndefined(options.remark) && isString(options.remark)) {
            params.remark = options.remark;
        }
        if(!isUndefined(options.consultPrice) && isBoolean(options.consultPrice)) {
            params.consultPrice = options.consultPrice;
        }
        if(!isUndefined(options.consultData) && isBoolean(options.consultData)) {
            params.consultData = options.consultData;
        }
        if(!isUndefined(options.telContact) && isBoolean(options.telContact)) {
            params.telContact = options.telContact;
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.SHOP.CREATE_GOODS_CONSULT.url,
                MS._config.parameters.SHOP.CREATE_GOODS_CONSULT.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }
}

module.exports = goodsConsult